/*
 * $Id: $
 */
package org.rcgwt.client.ui.grid.provider;

import org.rcgwt.client.ui.grid.event.OverElementEvent;
import org.rcgwt.client.ui.grid.event.OverElementHandler;
import org.rcgwt.client.ui.grid.internal.HandlerManagerProvider;
import org.rcgwt.client.ui.grid.internal.model.IElementModel;

import com.google.gwt.event.shared.HandlerRegistration;

/**
 * 
 * @author Olivier Oeuillot (latest modification by $Author: $)
 * @version $Revision: $ $Date: $
 */
public class BasicOverProvider extends HandlerManagerProvider implements
        IOverProvider {

    private IElementModel currentOverModelElement;

    @Override
    public IElementModel getOverElement() {
        return currentOverModelElement;
    }

    @Override
    public void setOverElement(IElementModel newElementModel) {

        if (currentOverModelElement == newElementModel) {
            return;
        }

        IElementModel old = currentOverModelElement;
        currentOverModelElement = newElementModel;

        OverElementEvent.fire(this, old, currentOverModelElement);
    }

    @Override
    public HandlerRegistration addOverElementHandler(
            OverElementHandler<IElementModel> handler) {
        return ensureHandlers().addHandler(OverElementEvent.getType(), handler);
    }
}
